package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.system.domain.MyCurriculmVitaeWorkAward;
import com.ruoyi.system.mapper.MyCurriculumVitaeMapper;
import com.ruoyi.system.domain.MyCurriculumVitae;
import com.ruoyi.system.service.IMyCurriculumVitaeService;

/**
 * 我的简历Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-12
 */
@Service
public class MyCurriculumVitaeServiceImpl implements IMyCurriculumVitaeService 
{
    @Autowired
    private MyCurriculumVitaeMapper myCurriculumVitaeMapper;

    /**
     * 查询我的简历
     * 
     * @param id 我的简历主键
     * @return 我的简历
     */
    @Override
    public MyCurriculumVitae selectMyCurriculumVitaeById(Long id)
    {
        return myCurriculumVitaeMapper.selectMyCurriculumVitaeById(id);
    }

    /**
     * 查询我的简历列表
     * 
     * @param myCurriculumVitae 我的简历
     * @return 我的简历
     */
    @Override
    public List<MyCurriculumVitae> selectMyCurriculumVitaeList(MyCurriculumVitae myCurriculumVitae)
    {
        return myCurriculumVitaeMapper.selectMyCurriculumVitaeList(myCurriculumVitae);
    }

    /**
     * 新增我的简历
     * 
     * @param myCurriculumVitae 我的简历
     * @return 结果
     */
    @Transactional
    @Override
    public int insertMyCurriculumVitae(MyCurriculumVitae myCurriculumVitae)
    {
        int rows = myCurriculumVitaeMapper.insertMyCurriculumVitae(myCurriculumVitae);
        insertMyCurriculmVitaeWorkAward(myCurriculumVitae);
        return rows;
    }

    /**
     * 修改我的简历
     * 
     * @param myCurriculumVitae 我的简历
     * @return 结果
     */
    @Transactional
    @Override
    public int updateMyCurriculumVitae(MyCurriculumVitae myCurriculumVitae)
    {
        myCurriculumVitaeMapper.deleteMyCurriculmVitaeWorkAwardByCurriculumVitaeId(myCurriculumVitae.getId());
        insertMyCurriculmVitaeWorkAward(myCurriculumVitae);
        return myCurriculumVitaeMapper.updateMyCurriculumVitae(myCurriculumVitae);
    }

    /**
     * 批量删除我的简历
     * 
     * @param ids 需要删除的我的简历主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteMyCurriculumVitaeByIds(Long[] ids)
    {
        myCurriculumVitaeMapper.deleteMyCurriculmVitaeWorkAwardByCurriculumVitaeIds(ids);
        return myCurriculumVitaeMapper.deleteMyCurriculumVitaeByIds(ids);
    }

    /**
     * 删除我的简历信息
     * 
     * @param id 我的简历主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteMyCurriculumVitaeById(Long id)
    {
        myCurriculumVitaeMapper.deleteMyCurriculmVitaeWorkAwardByCurriculumVitaeId(id);
        return myCurriculumVitaeMapper.deleteMyCurriculumVitaeById(id);
    }

    /**
     * 新增获奖信息
     * 
     * @param myCurriculumVitae 我的简历对象
     */
    public void insertMyCurriculmVitaeWorkAward(MyCurriculumVitae myCurriculumVitae)
    {
        List<MyCurriculmVitaeWorkAward> myCurriculmVitaeWorkAwardList = myCurriculumVitae.getMyCurriculmVitaeWorkAwardList();
        Long id = myCurriculumVitae.getId();
        if (StringUtils.isNotNull(myCurriculmVitaeWorkAwardList))
        {
            List<MyCurriculmVitaeWorkAward> list = new ArrayList<MyCurriculmVitaeWorkAward>();
            for (MyCurriculmVitaeWorkAward myCurriculmVitaeWorkAward : myCurriculmVitaeWorkAwardList)
            {
                myCurriculmVitaeWorkAward.setCurriculumVitaeId(id);
                list.add(myCurriculmVitaeWorkAward);
            }
            if (list.size() > 0)
            {
                myCurriculumVitaeMapper.batchMyCurriculmVitaeWorkAward(list);
            }
        }
    }
}
